package com.example.reference_book.util;

import com.example.reference_book.entity.CourseInfo;
import com.example.reference_book.filter.CourseFilter;
import com.example.reference_book.filter.courseImpl.CourseAroundFilter;
import com.example.reference_book.filter.courseImpl.CourseDeptFilter;
import com.example.reference_book.filter.courseImpl.CourseNameFilter;
import com.example.reference_book.filter.courseImpl.CourseSchoolFilter;

import java.util.List;

public class CourseSearchUtil {
    public static CourseSearchUtil searchUtil;
    public static List<CourseInfo> list;
    private CourseSearchUtil (){

    }

    public void init(List<CourseInfo> list) {
        this.list = list;
    }

    public static CourseSearchUtil getSearchUtil() {
        if (searchUtil == null) {
            synchronized (CourseSearchUtil.class) {
                if (searchUtil == null) {
                    searchUtil = new CourseSearchUtil();
                }
            }
        }
        return searchUtil;
    }

    public List<CourseInfo> searchByKey(int type, String key){
        CourseFilter filter;
        switch (type){
            case 1:{
                filter = new CourseSchoolFilter();
                break;
            }
            case 2:{
                filter = new CourseDeptFilter();
                break;
            }
            case 3:{
                filter = new CourseNameFilter();
                break;
            }
            default:
                filter = new CourseAroundFilter();
        }
        return filter.getList(key,list);
    }
}
